package com.gylang.commons.util;


import com.gylang.commons.vo.CryptResultVO;

import static com.gylang.commons.util.GResultUtils.*;

/**
 * @author gylang
 * data 2020/6/14
 * @version v0.0.1
 */
public class CryptResultUtils {
    /**
     * 默认code 200 msg 成功
     *
     * @param data 设置数据
     * @return 成功结果
     */
    public static CryptResultVO setData(Object data) {


        CryptResultVO result = new CryptResultVO();
        result.setData(data);
        result.setCode(DEF_SUCCESS_RESPONSE_CODE);
        result.setMsg(DEF_SUCCESS_RESPONSE_MSG);
        return result;

    }

    /**
     * 默认code 200 msg 成功
     *
     * @param data 设置数据
     * @return 成功结果
     */
    public static CryptResultVO setSuccess(String msg, Object data) {


        CryptResultVO cryptResultVO = setData(data);
        cryptResultVO.setMsg(msg);
        return cryptResultVO;
    }

    /**
     * 默认返回 code : -1 msg : 失败 data : null
     *
     * @return 失败结果
     */
    public static CryptResultVO setFail() {

        CryptResultVO result = new CryptResultVO();
        result.setCode(DEF_FAIL_RESPONSE_CODE);
        result.setMsg(DEF_FAIL_RESPONSE_MSG);
        return result;
    }

    /**
     * 失败返回
     *
     * @param code 失败code
     * @param msg  失败信息
     * @return 失败信息对象
     */
    public static CryptResultVO setFail(String code, String msg) {

        CryptResultVO cryptResultVO = new CryptResultVO();
        cryptResultVO.setCode(code);
        cryptResultVO.setMsg(msg);
        return cryptResultVO;
    }

    /**
     * 默认返回msg : 失败  data : null
     *
     * @param code 失败code
     * @return 失败信息
     */
    public static CryptResultVO setFailCode(String code) {

        CryptResultVO cryptResultVO = setFail();
        cryptResultVO.setCode(code);
        return cryptResultVO;
    }

    /**
     * 默认返回code : -1  data : null
     *
     * @param msg 失败信息
     * @return 失败信息
     */
    public static CryptResultVO setFailMsg(String msg) {

        CryptResultVO result = setFail();
        result.setMsg(msg);
        return result;
    }


}
